import React from 'react';
import {getAntd, getEcCom, getLabel} from '../../util/convert';
import {message} from 'antd';

export default class Main extends React.Component {
    constructor() {
        super();
        this.state = {showAll: false};
    }

    componentDidMount() {
        const {isSuccess = false} = this.props;
        isSuccess&&message.success(getLabel(21430, '流程处理成功'));
    }

    render() {
        const {showAll} = this.state;
        const {nodeNameValue, operators=[], isSuccess=false, nodeIds=''} = this.props;
        return (
            <div className="wf-confirm-msg">
                {
                    nodeIds != '' &&
                    <div className="wf-confirm-msg-content">
                        <div className="wf-confirm-msg-title">
                            <div
                                className="wf-confirm-msg-receiver-title">{getLabel(526435, '流程到达节点')}： {nodeNameValue}</div>
                        </div>

                        <div className="wf-confirm-msg-operators">
                            <div className="wf-confirm-msg-receiver-title">{getLabel(15525, '接收人')}：</div>
                            <div className="wf-confirm-msg-receiver-users">
                                {
                                    operators && operators.map((item, index) => {
                                        if (index >= 20 && !showAll)
                                            return null;
                                        return this.getOperatorObj(item);
                                    })
                                }
                                {
                                    operators.length > 20 && showAll &&
                                    <i className="icon-coms-up" onClick={this.controlShowAll.bind(this, false)}/>
                                }
                                {
                                    operators.length > 20 && !showAll &&
                                    <i className="icon-coms-down" onClick={this.controlShowAll.bind(this, true)}/>
                                }
                            </div>

                        </div>
                    </div>
                }
            </div>
        )
    }

    getOperatorObj(item) {
        let obj = new Array();
        if (!!item.beagentid) {    //存在代理
            obj.push(<a className="wea-hrm-card" href={`javaScript:openhrm(${item.beagentid})`}
                        onClick={event => window.pointerXY(event)}>{item.beagentname}</a>);
            obj.push(<span className="wf-confirm-msg-connect-symbol">-></span>);
        }
        obj.push(<a className="wea-hrm-card" href={`javaScript:openhrm(${item.operatorid})`}
                    onClick={event => window.pointerXY(event)}>{item.operatorname}</a>);
        return <span className="wf-confirm-msg-user">{obj}</span>;
    }

    controlShowAll(bool) {
        this.setState({showAll: bool})
    }

}
